package com.jinzhi.jzdoor.certificate.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
@Service
public class SmsLimitService {

    private Map<String, Integer> smsCounts = new HashMap<>();

    /**
     * 自增
     * @param phoneNumber
     */
    public void incrementCount(String phoneNumber) {
        smsCounts.put(phoneNumber, smsCounts.getOrDefault(phoneNumber,0) + 1);
    }

    /**
     * 获取验证码发送次数
     * @param phoneNumber
     * @return
     */
    public int getCount(String phoneNumber) {
        return smsCounts.get(phoneNumber);
    }

    /**
     * 重置验证码
     */
    public void resetCounts() {
        smsCounts.clear();
    }

    /**
     * 校验验证码的次数
     */
    public boolean checkCount(String phoneNumber) {
        Integer count = smsCounts.get(phoneNumber);
        if (count == null) {
            this.incrementCount(phoneNumber);
        } else if (count>5){
            return true;
        }else {
            return false;
        }
        return false;
    }

}
